﻿using System;
using System.Collections.Generic;
using System.Text;

namespace SupervisedSpeakerRecognition
{
    /// <summary>
    /// Class for computing the inverse Fast Fourier Transform (or DCT) on the Real part 
    /// </summary>
    public class IFFTCommand : ICommand
    {
        //************************  Private Fields  *******************************// 
        private Double[] inputData;
        private Complex[] outputComplexData;
        private double[] magnitudeData;
        private bool realOnly = true;
        //************************  Constructors    *******************************// 
        public IFFTCommand()
        {
        }

        public IFFTCommand(bool RealOnly)
        {
            realOnly = RealOnly;
        }
        //************************  Public Properties  ****************************// 
        public bool RealOnly
        {
            get { return realOnly; }
            set { realOnly = value; }
        }

        public Double[] MagnitudeData
        {
            get { return magnitudeData; }
            set { magnitudeData = value; }
        }

        public Complex[] OutputComplexData
        {
            get { return outputComplexData; }
            set { outputComplexData = value; }
        }

        public Double[] InputData
        {
            get { return inputData; }
            set { inputData = value; }
        }
        //************************  Public Methods  ****************************// 
        #region ICommand Members

        public void execute()
        {   // compute the inverse fft of the double array to return to Time Domain
            outputComplexData = FFT.ifft(FFT.convertToComplex(inputData));
            // get the magnitudes of the complex results according to the flag of Real or Image 
            magnitudeData = FFT.getMagnitude(outputComplexData, RealOnly);
        }
        #endregion
    }
}
